/*
 * Copyright (c) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "bridge/cj_frontend/cppview/data_change_listener.h"

#include "core/common/container_scope.h"

using namespace OHOS::Ace;
using namespace OHOS::Ace::Framework;

CJDataChangeListener::CJDataChangeListener() : FFIData()
{
    instanceId_ = ContainerScope::CurrentId();
}

void CJDataChangeListener::AddListener(const WeakPtr<V2::DataChangeListener>& listener)
{
    listeners_.emplace(listener);
}

void CJDataChangeListener::RemoveListener(const WeakPtr<V2::DataChangeListener>& listener)
{
    listeners_.erase(listener);
}

void CJDataChangeListener::OnDataReloaded()
{
    NotifyAll(&V2::DataChangeListener::OnDataReloaded);
}

void CJDataChangeListener::OnDataAdded(size_t index)
{
    NotifyAll(&V2::DataChangeListener::OnDataAdded, index);
}

void CJDataChangeListener::OnDataDeleted(size_t index)
{
    NotifyAll(&V2::DataChangeListener::OnDataDeleted, index);
}

void CJDataChangeListener::OnDataChanged(size_t index)
{
    NotifyAll(&V2::DataChangeListener::OnDataChanged, index);
}

void CJDataChangeListener::OnDataMoved(size_t from, size_t to)
{
    NotifyAll(&V2::DataChangeListener::OnDataMoved, from, to);
}
